package ar.edu.itba.pod.legajo48013.rmi;

import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import ar.edu.itba.node.NodeInformation;
import ar.edu.itba.pod.legajo48013.event.DisconnectThread;
import ar.edu.itba.pod.legajo48013.host.Host;

public class LookupUtil {
	
	public static Remote lookup(Host host, NodeInformation nodeInfo, String registry) {
		Remote remoteObj = null;
		try {
			Registry registryLook = LocateRegistry.getRegistry(nodeInfo.host(), nodeInfo.port());
			remoteObj = registryLook.lookup(registry);
		} catch (Exception e) { //Remote or NotBound exception
			new DisconnectThread(host, nodeInfo).start();
		}
		return remoteObj;
	}
}
